/*
 * Expr.cpp
 *
 *  Created on: 2010-12-18
 *      Author: lyyang
 */

#include "Expr.h"
#include <string>
using namespace std;

Expr::Expr(int v)
{
	node_ = new Int_node(v);
	node_->use_count_ = 1;
}

Expr::Expr(string op, Expr opnd)
{
	node_ = new Unary_node(op, opnd);
	node_->use_count_ = 1;
}

Expr::Expr(string op, Expr l, Expr r)
{
	node_ = new Binary_node(op, l, r);
	node_->use_count_ = 1;
}

Expr::Expr(const Expr &e)
{
	e.node_->use_count_++;
	node_ = e.node_;
}

Expr::~Expr()
{
	if (--node_->use_count_ == 0)
		delete node_;
}

void Expr::print(ostream& o)
{
	node_->print(o);
}

int Expr::eval()
{
	return node_->eval();
}


